<?php

namespace App\Services\ApplyGoldProductReselling;

use App\Models\GoldRecord;
use App\Models\User;
use Illuminate\Support\Collection;
use App\Jobs\ApplyGoldProductResellingJob;

class ApplyGoldProductBatchReselling
{
	protected User $user;

	protected array $pendingCacheIds = [];

	public function __construct(User $user, $pendingCacheIds)
	{
		$this->user = $user;
		$this->pendingCacheIds = $pendingCacheIds;
	}

	public function apply()
	{
		if (count($this->pendingCacheIds) <= 0) return;

		foreach ($this->pendingCacheIds as $cacheId) {
			$this->user->markRecordCacheReselling($cacheId);
			$queue = app()->environment('local') ? 'default' : 'resell_gold_record';
			dispatch(new ApplyGoldProductResellingJob($this->user, $cacheId))->onQueue($queue);
		}
	}
}
